/**
 * 初始化整体流量图标
 */
define(function(){
    var ec=require('echarts');
    require('echarts/chart/radar');
    require('echarts/chart/line');
    require('echarts/chart/bar');
    var zrnumber = require('echarts/util/number');

    var myChart = ec.init(document.getElementById('quality_radar')); 

    var myOption = {  
        title : {
            text: '招聘简历&职位质量匹配雷达图'
        },
        tooltip : {
            trigger: 'axis',
            formatter: function (params,ticket,callback) {
                        var res = params[0].indicator;
                        for (var i = 0, l = params.length; i < l; i++) {
                            var realVal = params[i].value;
                            // if(params[i].indicator!="展现" && params[i].indicator != "点击"){
                            //     realVal = (realVal/10).toFixed(2);  //数据放大了10倍
                            // }
                            res += '<br/>' + params[i].name + ' : ' + realVal;
                        }
                        return res;
             }                     
        },
        legend: {
            show: false,
            x : 'center',
            data:[]
        },
        toolbox: {
            show : false,
            feature : {
                mark : {show: true},
                dataView : {show: false, readOnly: true},
                restore : {show: true},
                saveAsImage : {show: true}
            }
        },
        calculable : true,
        polar : [
            {
                indicator : [
                    {text : '学历'},
                    {text : '薪资'},
                    {text : '工作经验'}
                ],
                center : ['50%', '65%'],
                radius : '90%'
            }
        ],
        series : [
            {
                name: '对比',
                type: 'radar',
                itemStyle: {
                    normal: {
                        areaStyle: {
                            type: 'default'
                        }
                    }
                },
                data : [
                    {
                        value : [9000,500,50],
                        name : '简历'
                    },
                    {
                        value : [7500, 72000, 38],
                        name : '职位'
                    }
                ]
            }
        ]
    };


    /**
     * 根据指标显示日数据
     * @param eventType= 2:第一次加载, 1:切换日，周，月刷新 , 0: 添加对比后又重新选择指标
     */
    function show(dateVal){
        var dateGroup = $('#qualityLineOption').attr('dateGrp');
        var statType = $('#qualityLineOption').attr('statType');

        var city = $('#city_quality').val();
        var cate = $('#cate_quality').val();

        var education = $('#education_quality').val();
        var salary = $('#salary_quality').val();
        var workYears = $('#workYears_quality').val();

        myChart.showLoading({ text: '正在努力的读取数据中...' });
        $.ajax({
            url: '/dashboard/resume/ajax/qualityMatch',
            type: 'post',
            async: true,
            data: {"chartType":"radar","statType":statType, "dateGroup":dateGroup,"dateVal":dateVal,"city":city,"cate":cate,"education":education,"salary":salary,"workYears":workYears},
            dataType: 'json',
            success: function(data, textStatus) {
                myOption.series[0].data[0].value = data.resumeData;                  
                myOption.series[0].data[1].value = data.jobData;                  
                
                myChart.setOption(myOption,true);
                myChart.hideLoading();
            },
            error : function() {
                myChart.hideLoading();
            }
        });
    }

    var zrUtil = require('zrender/tool/util');

    function getIndexByName(data,name) {
        var dataLength = data.length;
        for (var i = 0; i < dataLength; i++) {
            if (data[i] == name || typeof data[i].value != 'undefined' && data[i].value == name) {
                return i;
            }
        }
        return -1;
    }

    var EC={
        show:show,
        resize:function(){myChart.resize();}
    };

    return EC;
});

